<?php include_once($_SERVER['DOCUMENT_ROOT']."/controller/common/common_setting_unit.php");         // 引入通用的设置文件 ?>
<?php include_once($_SERVER['DOCUMENT_ROOT']."/controller/common/module/head.php"); // 引入通用的头部 ?>
<?php include_once("../controller/order-pepare-statistic.php");                     // 当前页面的控制器 ?>



<body>
<!--顶部栏-->
<div id="topbar"> <?php include $_SERVER['DOCUMENT_ROOT'] . '/controller/common/module/topbar.php'; ?></div>

<!--容器-->
<div id="container" class="<? echo $now_extender ?>">

    <!--侧边栏-->
    <div id="sidebar"><?php include $_SERVER['DOCUMENT_ROOT'] . '/controller/common/module/sidebar.php'; ?></div>


    <div id="content">
        <?php $page_title='订单统计';?>
        <?php include ROOT_PATH_.'/controlbase/module/mod-page-title.php'; ?>





<div class="detail-box  layui-form">

<div class="detail-boxes">



    <!--搜索框-->
    <?
        //搜索的项目用  equal_name，表示搜索条件 等于输入内容，对应为name的项
        //搜索的项目用  like_
        //less_
        //greater_
        //这样去拼凑一个语句出来。多个项的话，就用+）号隔开
    ?>

    <div class="select-box clearfix layui-form">
        <form action="order-pepare-statistic.php" >



            <div class="layui-form-item search-period">
                <label class="layui-form-label">时间段</label>

                <div class="layui-input-block">
                    <input type="text" name="greaterequal_ondate"
                           placeholder="请输入开始时间" autocomplete="off" class="layui-input laydate_date"
                           value="<?if($_REQUEST['greaterequal_ondate']){echo $_REQUEST['greaterequal_ondate'] ;} ?>" >
                    <span>-</span>
                    <input type="text" name="lessequal_ondate"
                           placeholder="请输入结束时间" autocomplete="off" class="layui-input laydate_date"
                           value="<?if($_REQUEST['lessequal_ondate']){echo $_REQUEST['lessequal_ondate'];} ?>"  >
                </div>

            </div>


            <input type="hidden" name="now_extender" value="<?echo $_REQUEST['now_extender']?>">

            <button class="layui-btn  layui-btn-sm" ><i class="layui-icon">&#xe615;</i> 查找</button>
            <a class="layui-btn white layui-btn-sm" href="data_list.php?now_extender=<?echo $_REQUEST['now_extender']?>" ><i class="layui-icon">&#x1006;</i> 重置</a>

            <a class="layui-btn white layui-btn-sm" target="_blank"
               href="pepare-export.php?greaterequal_ondate=<?echo $_REQUEST['greaterequal_ondate']?>&lessequal_ondate=<?echo $_REQUEST['lessequal_ondate']?>&now_extender=<?echo $_REQUEST['now_extender']?>" >
                <i class="layui-icon">&#xe62d;</i> 导出表格</a>


            <br class="clearfloat"/>
        </form>


    </div>



</div>

    <blockquote class="layui-elem-quote">
        <div>本报表可以查看每日每个产品的数量。周期内订单存在的产品，都会被统计出来。</div>
        <div>如需要具体哪个学校哪个班要多少产品，则可查看 <a href="detail-statistic.php"  style="color:red;">配送明细表</a></div>
    </blockquote>

<!--    //算除总数即可-->

<!--    生成一个空数据的layui表格-->

    <table class="layui-table">
        <colgroup>
            <col width="80">
            <col width="150">
            <col >
            <col >
        </colgroup>
        <thead>
        <tr>
            <th>序号</th>
            <th>日期</th>
            <th>星期</th>
            <?foreach ($product_list as $k=>$v){?>
                <th><?echo $v['product_name']?></th>
                <?;}?>
        </tr>
        </thead>
        <tbody>
        <? $n=0;?>
        <? for($i=strtotime($_REQUEST['greaterequal_ondate']);$i<=strtotime($_REQUEST['lessequal_ondate']);$i+=86400){?>
                <? $n++?>
            <tr>
                <td><?echo $n?></td>
                <td><?echo $indate=date("Y-m-d",$i)?></td>
                <td><?//输出星期几
                        if(date("w",$i)==0){
                            echo "星期日";
                        }
                        elseif(date("w",$i)==1){
                            echo "星期一";
                        }
                        elseif(date("w",$i)==2){
                            echo "星期二";
                        }
                        elseif(date("w",$i)==3){
                            echo "星期三";
                        }
                        elseif(date("w",$i)==4){
                            echo "星期四";
                        }
                        elseif(date("w",$i)==5){
                            echo "星期五";
                        }
                        elseif(date("w",$i)==6){
                            echo "星期六";
                        }

                        ?>

                        </td>


                <?foreach ($product_list as $k=>$v){?>

                <td>
                    <?
                        //如果$indate是周六周日的话,就不统计了
                        if(date("w",$i)==0 || date("w",$i)==6){
                            echo "0";
                        }
                        else{
                            //统计当天该产品的数量
                            echo $product_sum[$v['product_name']][]=count_by_item($table_prefix."order_detail",
                                "status = '正常' and ondate = '{$indate} 00:00:00' and product_name ='{$v['product_name']}'")
                                            ;}
                    ?>
                </td>
                    <?;}?>




            </tr>
        <?}?>
        <tr>
            <td></td>
            <td></td>
            <td>合计</td>
            <?foreach ($product_list as $k=>$v){?>

            <td>
                <?echo array_sum($product_sum[$v['product_name']])?>

            </td>
                <?;}?>

        </tr>


        </tbody>
    </table>







</div>
</div>

<!--content端點01-->
</div>
<!--maincontent端點01-->
<br class="clearfloat"/>
</div>
<!--container端點01-->
</div>


<?php include ROOT_PATH_ . "/controller/common/module/footer.php"; ?> </body>
</html>
